/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PanelRegistrarActividad.java
 *
 * Created on 19/10/2014, 05:06:12 PM
 */
package mx.com.ugto.caadi.asistencias.gui;

import mx.com.ugto.caadi.asistencias.bean.Actividad;
import mx.com.ugto.caadi.asistencias.dao.ActividadDAO;
import static mx.com.ugto.caadi.asistencias.util.GUIUtil.*;

/**
 *
 * @author Rolando
 */
public class PanelEditarActividad extends javax.swing.JPanel {

    Actividad actividad;
    ActividadDAO actividadDAO;

    /** Creates new form PanelRegistrarActividad */
    public PanelEditarActividad() {
        initComponents();
    }

    public Actividad getActividad() {
        return actividad;
    }

    public void setActividad(Actividad actividad) {
        this.actividad = actividad;
    }

    void actualizarVista() {
        txtDescripcionLarga.setText(actividad.getStrNombre());
        txtDescripcionCorta.setText(actividad.getStrNombreCorto());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblTitulo = new javax.swing.JLabel();
        lblDescripcionLarga = new javax.swing.JLabel();
        txtDescripcionLarga = new javax.swing.JTextField();
        lblDescripcionCorta = new javax.swing.JLabel();
        txtDescripcionCorta = new javax.swing.JTextField();
        btnLimpiar = new javax.swing.JButton();
        btnGuardar = new javax.swing.JButton();

        lblTitulo.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblTitulo.setText("MODIFICAR DATOS DE ACTIVIDADES");

        lblDescripcionLarga.setText("Descripción larga:");

        lblDescripcionCorta.setText("Descripción corta:");

        btnLimpiar.setText("Limpiar");

        btnGuardar.setText("Guardar");
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnGuardar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnLimpiar))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(lblTitulo)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(lblDescripcionLarga)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(txtDescripcionLarga, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(lblDescripcionCorta)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(txtDescripcionCorta))))
                .addContainerGap(164, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {lblDescripcionCorta, lblDescripcionLarga});

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {txtDescripcionCorta, txtDescripcionLarga});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblTitulo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblDescripcionLarga)
                    .addComponent(txtDescripcionLarga, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblDescripcionCorta)
                    .addComponent(txtDescripcionCorta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnLimpiar)
                    .addComponent(btnGuardar))
                .addContainerGap(193, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed
// TODO add your handling code here:
    editar();
}//GEN-LAST:event_btnGuardarActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnGuardar;
    private javax.swing.JButton btnLimpiar;
    private javax.swing.JLabel lblDescripcionCorta;
    private javax.swing.JLabel lblDescripcionLarga;
    private javax.swing.JLabel lblTitulo;
    private javax.swing.JTextField txtDescripcionCorta;
    private javax.swing.JTextField txtDescripcionLarga;
    // End of variables declaration//GEN-END:variables

    private void editar() {
        String descripcionLarga = txtDescripcionLarga.getText();
        String descripcionCorta = txtDescripcionCorta.getText();
        if (!descripcionLarga.isEmpty() && !descripcionCorta.isEmpty()) {
            actividad.setStrNombre(descripcionLarga);
            actividad.setStrNombreCorto(descripcionCorta);
            ActividadDAO dao = new ActividadDAO();
            dao.update(actividad);
            limpiar(this);
            Main.getInstance().buscarActividad();
        }
    }

    void obtenerFoco() {
        txtDescripcionLarga.requestFocusInWindow();
    }
}
